<template>
  <div id="list">
    <el-table
      :data="specslist"
      style="width: 100%"
      row-key="id"
      border
      lazy
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="用户编号" width="200">
      </el-table-column>
      <el-table-column prop="specsname" label="用户名" width="200">
      </el-table-column>
      <el-table-column  label="规格属性" width="200">
          <template slot-scope="scope">
            <div>
                <el-tag type="success" v-for="(item,index) in scope.row.attrs"
                :key="index" >{{item}}</el-tag>
            </div>
          </template>
      </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <div>
            <el-button type="success" v-if="scope.row.status == 1"
              >启用</el-button
            >
            <el-button type="danger" v-else>禁用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <div>
            <el-button type="primary" plain @click="edit(scope.row.id)">编 辑</el-button>
            <el-button type="primary" @click="del(scope.row.id)"
              >删 除</el-button
            >
          </div>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination background layout="prev, pager, next" :total="specstotal" :page-size="specssize" @current-change="change">
    </el-pagination>
  </div>
</template>
<script>
import { mapActions, mapGetters } from "vuex";
import {specsdelete}from "../../../requset/api";
import { successAlert,warningAlert } from "../../../util/alert.js";
export default {
  data() {
    return {
    }
  },
  computed:{
    ...mapGetters({
      specslist: "specs/list",
      specssize:"specs/size",
      specstotal:"specs/total"
    })
  },
  methods: {
    ...mapActions({
      reqChangeSpecs: "specs/reqChangeSpecs",
      reqChangePage: "specs/reqChangePage",
      reqChangeTotal: "specs/reqChangeTotal",
    }),
    edit(id){
      this.$emit("edit",id)
    },
    change(num){
      this.reqChangePage(num)
    },
    del(id){
       this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText:"确定",
        cancelButtonText: "取消",
        type:'success',
      }).then(() => {
          specsdelete({id:id}).then(res=>{
            if(res.data.code==200){
              successAlert(res.data.msg)
              this.reqChangeSpecs()
            }else{
              warningAlert(res.data.msg)
            }
          })
        }).catch(() => {
          warningAlert("已取消删除")
        });
    }
  },
  mounted(){
    this.reqChangePage(1)
    this.reqChangeTotal();
  }
};
</script>
<style>
</style>